package com.bjpowernode.controllers;

import com.bjpowernode.entities.TActivity;
import com.bjpowernode.querys.ActivityQuery;
import com.bjpowernode.result.Result;
import com.bjpowernode.services.ActivityService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ActivityController {
    @Resource
    private final ActivityService activityService;

    public ActivityController(ActivityService activityService) {
        this.activityService = activityService;
    }

    @GetMapping(value = "/api/activity/{id}")
    public Result getActivityById(@PathVariable(value = "id") Integer id) {
        TActivity tActivity = activityService.getActivityById(id);
        return Result.OK(tActivity);
    }

    @GetMapping(value = "/api/activities")
    public Result getActivitiesByPage(@RequestParam(value = "current") Integer current, ActivityQuery activityQuery) {
        PageInfo<TActivity> pageInfo = activityService.getActivityByPage(current, activityQuery);
        return Result.OK(pageInfo);
    }
}
